/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package action.organization;
import org.apache.struts2.interceptor.ServletRequestAware;
import service.OrgService;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import po.*;
import myUtils.Constants;
/**
 *
 * @author luyang
 */
public class OrgApproveUsrAction extends ActionSupport implements ServletRequestAware
{
    private HttpServletRequest request;
    private OrgService orgService;
    private User user;
    private Organization organization;
    private Userorgrelation userorgrelation;

    @Override
    public String execute()
    {
        String user_id=request.getParameter("user_id");
        String org_id=request.getParameter("org_id");
        String msg="";

        if(user_id==null || org_id==null)
        {
            msg="user_id or org_id is null";
        }
        else
        {
            user.setId(Integer.parseInt(user_id));
            organization.setId(Integer.parseInt(org_id));
            userorgrelation.setUser(user);
            userorgrelation.setOrganization(organization);
            userorgrelation.setState(Constants.ORG_MEMBER);
             userorgrelation.setJointtime(new Date());
            orgService.approveUser(userorgrelation);
            msg=Constants.SUCCESS_OPERATION;
        }
        request.setAttribute("msg", msg);


        return SUCCESS;
    }

    public void setOrgService(OrgService orgService)
    {
        this.orgService=orgService;
    }

    public void setServletRequest(HttpServletRequest request)
    {
        this.request=request;
    }

    public void setUser(User user)
    {
        this.user=user;
    }

    public void setOrganization(Organization organization)
    {
        this.organization = organization;
    }

    public void setUserorgrelation(Userorgrelation userorgrelation)
    {
        this.userorgrelation=userorgrelation;
    }

}
